package com.shopping.util;

import com.google.gson.JsonObject;
import com.shopping.common.ResultCode;

/**
 * @author 张衍斌
 * @version 1.0
 * @program dada-shopping
 * @description 返回信息类
 * @create 2019-08-05 15:43
 */
public class ResponseData {

    /**
     * @MethodName: success
     * @Description: 成功
     * @return: String
     * @Author: 张衍斌
     * @Date: 2019/8/5
     */
    public static String success() {
        JsonObject result = new JsonObject();
        result.addProperty("resultCode", ResultCode.success.getCode());
        result.addProperty("message", ResultCode.success.getMessage());
        return result.toString();
    }

    /**
     * @MethodName: failure
     * @Description: 失败
     * @return: String
     * @Author: 张衍斌
     * @Date: 2019/8/5
     */

    public static String failure() {
        JsonObject result = new JsonObject();
        result.addProperty("resultCode", ResultCode.failure.getCode());
        result.addProperty("message", ResultCode.failure.getMessage());
        return result.toString();
    }

    /**
     * @MethodName: customResult
     * @Description: 自定义
     * @Param: code
     * @Param: message
     * @return: String
     * @Author: 张衍斌
     * @Date: 2019/8/5
     */

    public static String customResult(int code, String message) {
        JsonObject result = new JsonObject();
        result.addProperty("resultCode", code);
        result.addProperty("message", message);
        return result.toString();
    }

    /**
     * @MethodName: resultData
     * @Description: 返回分页数据
     * @Param: code
     * @Param: message
     * @Param: data
     * @Param: totalNum
     * @Param: totalPage
     * @return: String
     * @Author: 张衍斌
     * @Date: 2019/8/5
     */

    public static String resultData(int code, String message, Object data, int totalNum, int totalPage) {
        JsonObject result = new JsonObject();
        result.addProperty("resultCode", code);
        result.addProperty("message", message);
        result.addProperty("data", data.toString());
        result.addProperty("totalNum", totalNum);
        result.addProperty("totalPage", totalPage);
        return result.toString();
    }
    /**
     * @MethodName: resultData
     * @Description: 返回数据
     * @Param: code
     * @Param: message
     * @Param: data
     * @return: String
     * @Author: 张衍斌
     * @Date: 2019/8/5
     */

    public static String resultData(int code, String message, Object data) {
        JsonObject result = new JsonObject();
        result.addProperty("resultCode", code);
        result.addProperty("message", message);
        result.addProperty("data", data.toString());
        return result.toString();
    }


}
